Count the frequency of words appearing in a string